﻿using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纺织贸易管理系统;

namespace BLL
{
  public   class 架子BLL
    {
        public static  void 架子出库(List<danjumingxitable> listmingxi,DanjuTable danju )
        {
            foreach (var m in listmingxi )
            {
                var kuwei = m.Kuwei.Split('-');
                if (kuwei.Length == 2)
                {
                    string guisuo = kuwei[1];
                    string jiaziID = kuwei[0];
                  Connect.dbcontext.Updateable<JiaziTable>().SetColumns(x =>new JiaziTable() { State = danju.ksmc }).Where(x => x.Guisuo == guisuo && x.JiaziID == jiaziID).ExecuteCommand();
                    //JiaziTableService.UpdateJiaziTable($"State='{danju.ksmc}'", );
                    var jiazi = Connect.dbcontext.Queryable<JiaziTable>().First(X => X.JiaziID == kuwei[0] && X.Guisuo == kuwei[1]);
                    if (jiazi != null)
                    {
                        Connect.dbcontext.Insertable(new ZhijiaMingxiTable()
                        {
                            Danhao = danju.dh,
                            Bianhao = jiazi.ID.ToString (),
                            _date = danju.rq,
                            Remarker = m.beizhu,
                            Leixing = "出库",
                            Kehu = danju.ksmc,
                            CarNum = danju.CarNum
                        }).ExecuteCommand();
                    }
                }
            }
        }
        public static void 架子入库(List<danjumingxitable> listmingxi)
        {
            foreach (var m in listmingxi)
            {
                if (m.Kuwei.Contains("-"))
                {
                    var kuwei = m.Kuwei.Split('-');
                    Connect.dbcontext.Updateable<JiaziTable>().SetColumns(x => x.State == "自己公司").Where(x => x.Guisuo == kuwei[1] && x.JiaziID == kuwei[0]).ExecuteCommand();
                    //JiaziTableService.UpdateJiaziTable($"State='自己公司'", x => x.Guisuo == kuwei[1] && x.JiaziID == kuwei[0]);
                }
            }
        }
        public static void 删除日志(string danhao)
        {
            Connect.dbcontext.Deleteable<ZhijiaMingxiTable>().Where(x => x.Danhao == danhao).ExecuteCommand();
           // ZhijiaMingxiTableService.DeleteZhijiaMingxiTable(x => x.Danhao == danhao);
        }
    }
}
